1. Field of the Invention
The present invention relates to the field of computer software and, more particularly, to stateful session Enterprise Java Beans.
2. Description of the Related Art
ENTERPRISE JAVA BEANS (EJB) are reusable and portable software components that model business objects and processes. EJBs can run on any EJB enterprise server compliant with the JAVA 2 ENTERPRISE EDITION (J2EE) specification. The EJB server can manage many significant overhead issues such as object persistence, security, and transaction management. There are multiple types of EJBs including entity beans, session beans, and message driven beans.
A session EJB is a reusable component that maintains conversations or sessions with clients. The creation of a session EJB can require startup overhead such as allocating sufficient memory for the EJB and initializing reference variables for the EJB. The first client to request access to a session EJB can experience a performance lag when no pre-existing EJB is available for use due to the overhead in creating a new EJB instance. This overhead can cause a delay in program execution. The resulting delay can be unacceptable in many situations, including situations where real-time and/or near real-time responses are necessary. Two types of session EJBs are stateful and stateless EJBs.
A stateful session EJB maintains a conversational state with one client for the duration of a single session. This implies that the stateful session EJB can maintain instance variables across multiple invocations from the same client during a single session. Once the client finishes interacting with the stateful session EJB, the session for the EJB ends and all state data for the stateful session EJB is discarded. Stateful session EJBs are constructed every time a client requests a bean. Notably, stateful session EJBs are not pooled for reuse, thereby causing each new client call for a stateful session EJB to experience performance delays associated with instantiating a new stateful session EJB.
A stateless session EJB does not maintain a conversational state for each individual client. When a client requests a stateless session EJB, the client receives an existing instance from a pool of previously created stateless session EJBs. If no previously created EJBs exist in the pool, a new instance is created. A stateless session EJB is removed from the pool for the duration of any method call from a client. After the method completes, the stateless session EJB is returned to the pool. The transient nature of stateless session EJBs allows an EJB container to reuse EJB instances, which may optimize performance in many situations.
Each invocation of a stateless session EJB should be considered as a request to a brand new object instance, since any instance-variable state will be lost between invocations. That is, subsequent methods invoked by the same client against the same bean are not guaranteed to be performed by the same stateless session EJB instance since the bean container randomly retrieves a free stateless session EJB from the bean pool for each invocation. Accordingly, operations that require variable state information to be maintained cannot be performed using conventional stateless session EJBs. For example, a stateless session EJB should not be used to manage a process that may have to be interrupted before completion because the variable state information required to programmatically interrupt the process will not be maintained by the stateless session EJB.